package com.itheima.customer.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.itheima.customer.dao.ICustomerDao;
import com.itheima.customer.domain.Customer;

/**
 * 客户的持久层实现类
 * @author Administrator
 *
 */
@Repository("customerDao")
public class CustomerDaoImpl extends BaseDaoImpl<Customer> implements ICustomerDao{

	@Autowired
	private HibernateTemplate hibernateTemplate;
	
/*	
	@Override
	public void save(Customer customer) {
		
		hibernateTemplate.save(customer);

	}*/

/*	@Override
	public List<Customer> findAll(DetachedCriteria dCriteria) {
		
		return (List<Customer>) hibernateTemplate.findByCriteria(dCriteria);
	}*/
	@Override
	public Customer findCustomer(Customer customer) {
		return (Customer) hibernateTemplate.load(Customer.class,((com.itheima.customer.domain.Customer) customer).getCustId());
	}
/*
	@Override
	public void update(Customer customer) {

		hibernateTemplate.update(customer);
	}*/

	/*@Override
	public void delete(Customer customer) {

		hibernateTemplate.delete(customer);
	}
*/
	
	@Override
	public List<Customer> findAllCustomers() {
		//必须提供构造方法
		return (List<Customer>) hibernateTemplate.find("select new com.itheima.customer.domain.Customer(custId,custName) from Customer");
	}

	@Override
	public Customer findCustomerById(Long custId) {
		
		return hibernateTemplate.get(Customer.class, custId);
	}
	
}
